home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / umoria / spells.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-28  |  54.8 KB  |  2,606 lines

  1. #include <stdio.h>
  2.  
  3. #include "constants.h"
  4. #include "config.h"
  5. #include "types.h"
  6. #include "externs.h"
  7.  
  8. #ifdef USG
  9. #include <string.h>
  10. #else
  11. #include <strings.h>
  12. #endif
  13.  
  14. #ifdef sun   /* correct SUN stupidity in the stdio.h file */
  15. char *sprintf();
  16. #endif
  17.  
  18. extern char cur_char2();
  19.  
  20. /* Following are spell procedure/functions            -RAK-    */
  21. /* These routines are commonly used in the scroll, potion, wands, and    */
  22. /* staves routines, and are occasionally called from other areas.         */
  23. /* Now included are creature spells also...                      -RAK    */
  24.  
  25. monster_name (m_name, m_ptr, r_ptr)
  26. char *m_name;
  27. monster_type *m_ptr;
  28. creature_type *r_ptr;
  29. {
  30.   if ((!m_ptr->ml) || (py.flags.blind > 0) ||
  31.       ((0x10000 & r_ptr->cmove) && (!py.flags.see_inv)))
  32.     (void) strcpy (m_name, "It");
  33.   else
  34.     (void) sprintf (m_name, "The %s", r_ptr->name);
  35. }
  36.  
  37. lower_monster_name (m_name, m_ptr, r_ptr)
  38. char *m_name;
  39. monster_type *m_ptr;
  40. creature_type *r_ptr;
  41. {
  42.   if ((!m_ptr->ml) || (py.flags.blind > 0) ||
  43.       ((0x10000 & r_ptr->cmove) && (!py.flags.see_inv)))
  44.     (void) strcpy (m_name, "it");
  45.   else
  46.     (void) sprintf (m_name, "the %s", r_ptr->name);
  47. }
  48.  
  49. /* Sleep creatures adjacent to player            -RAK-    */
  50. int sleep_monsters1(y, x)
  51. int y, x;
  52. {
  53.   register int i, j;
  54.   register cave_type *c_ptr;
  55.   register monster_type *m_ptr;
  56.   register creature_type *r_ptr;
  57.   int sleep;
  58.   vtype out_val;
  59.   vtype m_name;
  60.  
  61.   sleep = FALSE;
  62.   for (i = y-1; i <= y+1; i++)
  63.     for (j = x-1; j <= x+1; j++)
  64.       {
  65.     c_ptr = &cave[i][j];
  66.     if (c_ptr->cptr > 1)
  67.       {
  68.         m_ptr = &m_list[c_ptr->cptr];
  69.         r_ptr = &c_list[m_ptr->mptr];
  70.  
  71.         monster_name (m_name, m_ptr, r_ptr);
  72.         if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
  73.         (0x1000 & r_ptr->cdefense))
  74.           {
  75.         (void) sprintf(out_val, "%s is unaffected.", m_name);
  76.         msg_print(out_val);
  77.           }
  78.         else
  79.           {
  80.         sleep = TRUE;
  81.         m_ptr->csleep = 500;
  82.         (void) sprintf(out_val, "%s falls asleep.", m_name);
  83.         msg_print(out_val);
  84.           }
  85.       }
  86.       }
  87.   return(sleep);
  88. }
  89.  
  90. /* Detect any treasure on the current panel        -RAK-    */
  91. int detect_treasure()
  92. {
  93.   register int i, j;
  94.   register int detect;
  95.   register cave_type *c_ptr;
  96.  
  97.   detect = FALSE;
  98.   for (i = panel_row_min; i <= panel_row_max; i++)
  99.     for (j = panel_col_min; j <= panel_col_max; j++)
  100.       {
  101.     c_ptr = &cave[i][j];
  102.     if (c_ptr->tptr != 0)
  103.       if (t_list[c_ptr->tptr].tval == 100)
  104.         if (!test_light(i, j))
  105.           {
  106.         lite_spot(i, j);
  107.         c_ptr->tl = TRUE;
  108.         detect = TRUE;
  109.           }
  110.       }
  111.   return(detect);
  112. }
  113.  
  114.  
  115. /* Detect all objects on the current panel        -RAK-    */
  116. int detect_object()
  117. {
  118.   register int i, j;
  119.   register int detect;
  120.   register cave_type *c_ptr;
  121.  
  122.   detect = FALSE;
  123.   for (i = panel_row_min; i <= panel_row_max; i++)
  124.     for (j = panel_col_min; j <= panel_col_max; j++)
  125.       {
  126.     c_ptr = &cave[i][j];
  127.     if (c_ptr->tptr != 0)
  128.       if (t_list[c_ptr->tptr].tval < 100)
  129.         if (!test_light(i, j))
  130.           {
  131.         lite_spot(i, j);
  132.         c_ptr->tl = TRUE;
  133.         detect = TRUE;
  134.           }
  135.       }
  136.   return(detect);
  137. }
  138.  
  139.  
  140. /* Locates and displays traps on current panel        -RAK-    */
  141. int detect_trap()
  142. {
  143.   register int i, j;
  144.   int detect;
  145.   register cave_type *c_ptr;
  146.   register treasure_type *t_ptr;
  147.  
  148.   detect = FALSE;
  149.   for (i = panel_row_min; i <= panel_row_max; i++)
  150.     for (j = panel_col_min; j <= panel_col_max; j++)
  151.       {
  152.     c_ptr = &cave[i][j];
  153.     if (c_ptr->tptr != 0)
  154.       if (t_list[c_ptr->tptr].tval == 101)
  155.         {
  156.           change_trap(i, j);
  157.           c_ptr->fm = TRUE;
  158.           detect = TRUE;
  159.         }
  160.       else if (t_list[c_ptr->tptr].tval == 2)
  161.         {
  162.           t_ptr = &t_list[c_ptr->tptr];
  163.           known2(t_ptr->name);
  164.         }
  165.       }
  166.   return(detect);
  167. }
  168.  
  169.  
  170. /* Locates and displays all secret doors on current panel -RAK-    */
  171. int detect_sdoor()
  172. {
  173.   register int i, j;
  174.   register int detect;
  175.   register cave_type *c_ptr;
  176.  
  177.   detect = FALSE;
  178.   for (i = panel_row_min; i <= panel_row_max; i++)
  179.     for (j = panel_col_min; j <= panel_col_max; j++)
  180.       {
  181.     c_ptr = &cave[i][j];
  182.     if (c_ptr->tptr != 0)
  183.       /* Secret doors  */
  184.       if (t_list[c_ptr->tptr].tval == 109)
  185.         {
  186.           c_ptr->fval = corr_floor3.ftval;
  187.           change_trap(i, j);
  188.           c_ptr->fm = TRUE;
  189.           detect = TRUE;
  190.         }
  191.     /* Staircases    */
  192.       else if ((t_list[c_ptr->tptr].tval == 107) ||
  193.            (t_list[c_ptr->tptr].tval == 108))
  194.         if (!c_ptr->fm)
  195.           {
  196.         c_ptr->fm = TRUE;
  197.         lite_spot(i, j);
  198.         detect = TRUE;
  199.           }
  200.       }
  201.   return(detect);
  202. }
  203.  
  204.  
  205. /* Locates and displays all invisible creatures on current panel -RAK-*/
  206. int detect_invisible()
  207. {
  208.   register int i;
  209.   register int flag;
  210.   char tmp_str[2];
  211.   register monster_type *m_ptr;
  212.  
  213.   flag = FALSE;
  214.   i = muptr;
  215.   while (i > 0)
  216.     {
  217.       m_ptr = &m_list[i];
  218.       if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx))
  219.     if (0x10000 & c_list[m_ptr->mptr].cmove)
  220.       {
  221.         m_ptr->ml = TRUE;
  222.         tmp_str[0] = c_list[m_ptr->mptr].cchar;
  223.         tmp_str[1] = '\0';
  224.         print(tmp_str, (int)m_ptr->fy, (int)m_ptr->fx);
  225.         flag = TRUE;
  226.       }
  227.       i = m_list[i].nptr;
  228.     }
  229.   if (flag)
  230.     {
  231.       msg_print("You sense the presence of invisible creatures!");
  232.       /* make sure player sees the message */
  233.       msg_print(" ");
  234.       msg_flag = FALSE;
  235.     }
  236.   return(flag);
  237. }
  238.  
  239.  
  240. /* Light an area: 1.  If corridor  light immediate area -RAK-*/
  241. /*                2.  If room  light entire room.            */
  242. int light_area(y, x)
  243. register int y, x;
  244. {
  245.   register int i, j;
  246.   register int light;
  247.  
  248.   msg_print("You are surrounded by a white light.");
  249.   light = TRUE;
  250.   if (((cave[y][x].fval == 1) || (cave[y][x].fval == 2)) && (dun_level > 0))
  251.     light_room(y, x);
  252.   else
  253.     for (i = y-1; i <= y+1; i++)
  254.       for (j = x-1; j <=  x+1; j++)
  255.     if (in_bounds(i, j))
  256.       {
  257.         if (!test_light(i, j))
  258.           lite_spot(i, j);
  259.         cave[i][j].pl = TRUE;
  260.       }
  261.   return(light);
  262. }
  263.  
  264.  
  265. /* Darken an area, opposite of light area        -RAK-    */
  266. int unlight_area(y, x)
  267. int y, x;
  268. {
  269.   register int i, j, k;
  270.   int tmp1, tmp2;
  271.   int start_row, start_col;
  272.   int end_row, end_col;
  273.   int flag;
  274.   int unlight;
  275.   register cave_type *c_ptr;
  276.   vtype out_val;
  277.  
  278.   flag = FALSE;
  279.   if (((cave[y][x].fval == 1) || (cave[y][x].fval == 2)) && (dun_level > 0))
  280.     {
  281.       tmp1 = (SCREEN_HEIGHT/2);
  282.       tmp2 = (SCREEN_WIDTH /2);
  283.       start_row = (y/tmp1)*tmp1 + 1;
  284.       start_col = (x/tmp2)*tmp2 + 1;
  285.       end_row = start_row + tmp1 - 1;
  286.       end_col = start_col + tmp2 - 1;
  287.       for (i = start_row; i <= end_row; i++)
  288.     {
  289.       out_val[0] = '\0';
  290.       k = 0;
  291.       for (j = start_col; j <= end_col; j++)
  292.         {
  293.           c_ptr = &cave[i][j];
  294.           if ((c_ptr->fval == 1) || (c_ptr->fval == 2))
  295.         {
  296.           c_ptr->pl = FALSE;
  297.           c_ptr->fval = 1;
  298.           if (!test_light(i, j))
  299.             {
  300.               if (k == 0)
  301.             k = j;
  302.               (void) strcat(out_val, " ");
  303.             }
  304.           else if (k > 0)
  305.             {
  306.               flag = TRUE;
  307.               print(out_val, i, k);
  308.               out_val[0] = '\0';
  309.               k = 0;
  310.             }
  311.         }
  312.           else if (k > 0)
  313.         {
  314.           flag = TRUE;
  315.           print(out_val, i, k);
  316.           out_val[0] = '\0';
  317.           k = 0;
  318.         }
  319.           if (k > 0)
  320.         {
  321.           flag = TRUE;
  322.           print(out_val, i, k);
  323.         }
  324.         }
  325.     }
  326.     }
  327.   else
  328.     for (i = y-1; i <= y+1; i++)
  329.       for (j = x-1; j <= x+1; j++)
  330.     if (in_bounds(i, j))
  331.       {
  332.         c_ptr = &cave[i][j];
  333.         if ((c_ptr->fval == 4) || (c_ptr->fval == 5) || (c_ptr->fval ==6))
  334.           if (c_ptr->pl)
  335.         {
  336.           c_ptr->pl = FALSE;
  337.           flag = TRUE;
  338.         }
  339.         if (flag)
  340.           {
  341.         msg_print("Darkness surrounds you...");
  342.         unlight = TRUE;
  343.           }
  344.       }
  345.     else
  346.       unlight = FALSE;
  347.   return(unlight);
  348. }
  349.  
  350.  
  351. /* Map the current area plus some            -RAK-    */
  352. int map_area()
  353. {
  354.   register cave_type *c_ptr;
  355.   register int i7, i8, n, m;
  356.   int i, j, k, l;
  357.   int map;
  358.  
  359.   map = TRUE;
  360.   i = panel_row_min - randint(10);
  361.   j = panel_row_max + randint(10);
  362.   k = panel_col_min - randint(20);
  363.   l = panel_col_max + randint(20);
  364.   for (m = i; m <= j; m++)
  365.     for (n = k; n <= l; n++)
  366.       if (in_bounds(m, n))
  367.     if (set_floor(cave[m][n].fval))
  368.       for (i7 = m-1; i7 <= m+1; i7++)
  369.         for (i8 = n-1; i8 <= n+1; i8++)
  370.           {
  371.         c_ptr = &cave[i7][i8];
  372.         if (((c_ptr->fval >= 10) && (c_ptr->fval <= 12)) ||
  373.             (c_ptr->fval == 15))
  374.           c_ptr->pl = TRUE;
  375.         else if (c_ptr->tptr != 0)
  376.           if ((t_list[c_ptr->tptr].tval >= 102) &&
  377.               (t_list[c_ptr->tptr].tval <= 110) &&
  378.               (t_list[c_ptr->tptr].tval != 106))
  379.             c_ptr->fm = TRUE;
  380.           }
  381.   prt_map();
  382.   return(map);
  383. }
  384.  
  385.  
  386. /* Identify an object                    -RAK-    */
  387. int ident_spell()
  388. {
  389.   int item_val;
  390.   vtype out_val, tmp_str;
  391.   int redraw;
  392.   int ident;
  393.   register treasure_type *i_ptr;
  394.  
  395.   ident = FALSE;
  396.   redraw = FALSE;
  397.   if (get_item(&item_val, "Item you wish identified?",
  398.            &redraw, 0, inven_ctr-1))
  399.     {
  400.       i_ptr = &inventory[item_val];
  401.       ident = TRUE;
  402.       identify(inventory[item_val]);
  403.       known2(i_ptr->name);
  404.       objdes(tmp_str, item_val, TRUE);
  405.       (void) sprintf(out_val, "%c%c %s", item_val+97, cur_char2(item_val),
  406.              tmp_str);
  407.       msg_print(out_val);
  408.     }
  409.   if (redraw)
  410.     {
  411.       /* make sure player sees message before draw cave erases it */
  412.       msg_print(" ");
  413.       draw_cave();
  414.     }
  415.   return(ident);
  416. }
  417.  
  418.  
  419. /* Get all the monsters on the level pissed off...    -RAK-    */
  420. int aggravate_monster  (dis_affect)
  421. int dis_affect;
  422. {
  423.   register int i;
  424.   int aggravate;
  425.   register monster_type *m_ptr;
  426.  
  427.   aggravate = TRUE;
  428.   i = muptr;
  429.   while (i > 0)
  430.     {
  431.       m_ptr = &m_list[i];
  432.       m_ptr->csleep = 0;
  433.       if (m_ptr->cdis <= dis_affect)
  434.     if (m_ptr->cspeed < 2)
  435.       m_ptr->cspeed++;
  436.       i = m_list[i].nptr;
  437.     }
  438.   return(aggravate);
  439. }
  440.  
  441.  
  442. /* Surround the fool with traps (chuckle)        -RAK-    */
  443. int trap_creation()
  444. {
  445.   register int i, j;
  446.   register int trap;
  447.   register cave_type *c_ptr;
  448.  
  449.   trap = TRUE;
  450.   for (i = char_row-1; i <= char_row+1; i++)
  451.     for (j = char_col-1; j <= char_col+1; j++)
  452.       {
  453.     c_ptr = &cave[i][j];
  454.     if (set_floor(c_ptr->fval))
  455.       {
  456.         if (c_ptr->tptr != 0)
  457.           (void) delete_object(i, j);
  458.         place_trap(i, j, 1, randint(MAX_TRAPA)-1);
  459.       }
  460.       }
  461.   return(trap);
  462. }
  463.  
  464.  
  465. /* Surround the player with doors...            -RAK-    */
  466. int door_creation()
  467. {
  468.   register int i, j;
  469.   int k;
  470.   register int door;
  471.   register cave_type *c_ptr;
  472.  
  473.   door = TRUE;
  474.   for (i = char_row-1; i <= char_row+1; i++)
  475.     for (j = char_col-1; j <=  char_col+1; j++)
  476.       if ((i != char_row) || (j != char_col))
  477.     {
  478.       c_ptr = &cave[i][j];
  479.       if (set_floor(c_ptr->fval))
  480.         {
  481.           popt(&k);
  482.           if (c_ptr->tptr != 0)
  483.         (void) delete_object(i, j);
  484.           c_ptr->fopen = FALSE;
  485.           c_ptr->tptr = k;
  486.           t_list[k] = door_list[1];
  487.           if (test_light(i, j))
  488.         lite_spot(i, j);
  489.         }
  490.     }
  491.   return(door);
  492. }
  493.  
  494.  
  495. /* Destroys any adjacent door(s)/trap(s)         -RAK-    */
  496. int td_destroy()
  497. {
  498.   register int i, j;
  499.   register int destroy;
  500.   register cave_type *c_ptr;
  501.  
  502.   destroy = FALSE;
  503.   for (i = char_row-1; i <= char_row+1; i++)
  504.     for (j = char_col-1; j <= char_col+1; j++)
  505.       {
  506.     c_ptr = &cave[i][j];
  507.     if (c_ptr->tptr != 0)
  508.       {
  509.         if (((t_list[c_ptr->tptr].tval >= 101) &&
  510.          (t_list[c_ptr->tptr].tval <= 105) &&
  511.          (t_list[c_ptr->tptr].tval != 103)) ||
  512.         (t_list[c_ptr->tptr].tval == 109))
  513.           {
  514.         if (delete_object(i, j))
  515.           destroy = TRUE;
  516.           }
  517.         else if (t_list[c_ptr->tptr].tval == 2)
  518.           /* destroy traps on chest and unlock */
  519.           t_list[c_ptr->tptr].flags &= 0xFF000000;
  520.       }
  521.       }
  522.   return(destroy);
  523. }
  524.  
  525.  
  526. /* Display all creatures on the current panel        -RAK-    */
  527. int detect_monsters()
  528. {
  529.   register int i;
  530.   register int flag, detect;
  531.   char tmp_str[2];
  532.   register monster_type *m_ptr;
  533.  
  534.   flag = FALSE;
  535.   i = muptr;
  536.   while (i > 0)
  537.     {
  538.       m_ptr = &m_list[i];
  539.       if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx))
  540.     if ((0x10000 & c_list[m_ptr->mptr].cmove) == 0)
  541.       {
  542.         m_ptr->ml = TRUE;
  543.         tmp_str[0] = c_list[m_ptr->mptr].cchar;
  544.         tmp_str[1] = '\0';
  545.         print(tmp_str, (int)m_ptr->fy, (int)m_ptr->fx);
  546.         flag = TRUE;
  547.       }
  548.       i = m_list[i].nptr;
  549.     }
  550.   if (flag)
  551.     {
  552.       msg_print("You sense the presence of monsters!");
  553.       /* make sure player sees the message */
  554.       msg_print(" ");
  555.       msg_flag = FALSE;
  556.       detect = TRUE;
  557.     }
  558.   detect = flag;
  559.   return(detect);
  560. }
  561.  
  562.  
  563. /* Leave a line of light in given dir, blue light can sometimes    */
  564. /* hurt creatures...                                     -RAK-   */
  565. light_line(dir, y, x)
  566. int dir, y, x;
  567. {
  568.   register int i;
  569.   register cave_type *c_ptr;
  570.   register monster_type *m_ptr;
  571.   register creature_type *r_ptr;
  572.   vtype out_val;
  573.   vtype m_name;
  574.   char tmp_str[2];
  575.  
  576.   while (cave[y][x].fopen){
  577.       c_ptr = &cave[y][x];
  578.       if (panel_contains(y, x))
  579.     {
  580.       if ((!c_ptr->tl) && (!c_ptr->pl))
  581.         if (c_ptr->fval == 2)
  582.           light_room(y, x);
  583.         else
  584.           lite_spot(y, x);
  585.       if (c_ptr->cptr > 1)
  586.         {
  587.           m_ptr = &m_list[c_ptr->cptr];
  588.           r_ptr = &c_list[m_ptr->mptr];
  589.           m_ptr->ml = TRUE;
  590.           tmp_str[0] = r_ptr->cchar;
  591.           tmp_str[1] = '\0';
  592.           print(tmp_str, (int)m_ptr->fy, (int)m_ptr->fx);
  593.           monster_name (m_name, m_ptr, r_ptr);
  594.           if (0x0100 & r_ptr->cdefense)
  595.         {
  596.           (void) sprintf(out_val, "%s wails out in pain!", m_name);
  597.           msg_print(out_val);
  598.           i = mon_take_hit((int)c_ptr->cptr, damroll("2d8"));
  599.           if (i >= 0)
  600.             {
  601.               (void) sprintf(out_val, "%s dies in a fit of agony.",
  602.                      m_name);
  603.               msg_print(out_val);
  604.             }
  605.         }
  606.         }
  607.       c_ptr->pl = TRUE;
  608.     }
  609.       (void) move(dir, &y, &x);
  610.     }
  611. }
  612.  
  613.  
  614. /* Light line in all directions                -RAK-    */
  615. int starlite(y, x)
  616. register int y, x;
  617. {
  618.   register int i;
  619.  
  620.   msg_print("The end of the staff bursts into a blue shimmering light.");
  621.   for (i = 1; i <= 9; i++)
  622.     if (i != 5)
  623.       light_line(i, y, x);
  624.   return(TRUE);
  625. }
  626.  
  627.  
  628. /* Disarms all traps/chests in a given direction     -RAK-    */
  629. int disarm_all(dir, y, x)
  630. int dir, y, x;
  631. {
  632.   register cave_type *c_ptr;
  633.   register treasure_type *t_ptr;
  634.   register int i, oldy, oldx;
  635.   int disarm;
  636.   char *string;
  637.  
  638.   disarm = FALSE;
  639.   do
  640.     {
  641.       c_ptr = &cave[y][x];
  642.       if (c_ptr->tptr != 0)
  643.     {
  644.       t_ptr = &t_list[c_ptr->tptr];
  645.       if ((t_ptr->tval == 101) || (t_ptr->tval == 102))
  646.         {
  647.           if (delete_object(y, x))
  648.         disarm = TRUE;
  649.         }
  650.       else if (t_ptr->tval == 105)
  651.         {
  652.           t_ptr->p1 = 0;
  653.         }
  654.       else if (t_ptr->tval == 109)
  655.         {
  656.           c_ptr->fval = corr_floor3.ftval;
  657.           change_trap(y, x);
  658.           c_ptr->fm = TRUE;
  659.           disarm = TRUE;
  660.         }
  661.       else if (t_ptr->tval == 2)
  662.         if (t_ptr->flags != 0)
  663.           {
  664.         msg_print("Click!");
  665.         t_ptr->flags = 0;
  666.         disarm = TRUE;
  667.         string = index(t_ptr->name, '(');
  668.         if (string)
  669.           i = strlen(t_ptr->name) - strlen(string);
  670.         else
  671.           i = -1;
  672.         if (i >= 0)
  673.           t_ptr->name[i] = '\0';
  674.         (void) strcat(t_ptr->name, " (Unlocked)");
  675.         known2(t_ptr->name);
  676.           }
  677.     }
  678.       oldy = y;
  679.       oldx = x;
  680.       (void) move(dir, &y, &x);
  681.     }
  682.   while (cave[oldy][oldx].fopen);
  683.   return(disarm);
  684. }
  685.  
  686.  
  687. /* Return flags for given type area affect        -RAK-    */
  688. get_flags(typ, weapon_type, harm_type, destroy)
  689. int typ;
  690. int *weapon_type, *harm_type;
  691. int (**destroy)();
  692. {
  693.   int set_null(), set_fire_destroy(), set_frost_destroy();
  694.   int set_acid_destroy(), set_lightning_destroy();
  695.  
  696.   switch(typ)
  697.     {
  698.     case 1:      /* Lightning     */
  699.       *weapon_type = 0x00080000;
  700.       *harm_type   = 0x0100;
  701.       *destroy     = set_lightning_destroy;
  702.       break;
  703.     case 2:      /* Poison Gas    */
  704.       *weapon_type = 0x00100000;
  705.       *harm_type   = 0x0040;
  706.       *destroy     = set_null;
  707.       break;
  708.     case 3:      /* Acid          */
  709.       *weapon_type = 0x00200000;
  710.       *harm_type   = 0x0080;
  711.       *destroy     = set_acid_destroy;
  712.       break;
  713.     case 4:      /* Frost         */
  714.       *weapon_type = 0x00400000;
  715.       *harm_type   = 0x0010;
  716.       *destroy     = set_frost_destroy;
  717.       break;
  718.     case 5:      /* Fire          */
  719.       *weapon_type = 0x00800000;
  720.       *harm_type   = 0x0020;
  721.       *destroy     = set_fire_destroy;
  722.       break;
  723.     case 6:      /* Holy Orb      */
  724.       *weapon_type = 0x00000000;
  725.       *harm_type   = 0x0004;
  726.       *destroy     = set_null;
  727.       break;
  728.     default:
  729.       *weapon_type = 0;
  730.       *harm_type   = 0;
  731.       *destroy     = set_null;
  732.     }
  733. }
  734.  
  735.  
  736. /* Shoot a bolt in a given direction            -RAK-    */
  737. int fire_bolt(typ, dir, y, x, dam, bolt_typ)
  738. int typ, dir, y, x, dam;
  739. ctype bolt_typ;
  740. {
  741.   int i, oldy, oldx, dist;
  742.   int weapon_type, harm_type;
  743.   int flag;
  744.   int (*dummy)();
  745.   register cave_type *c_ptr;
  746.   register monster_type *m_ptr;
  747.   register creature_type *r_ptr;
  748.   vtype out_val;
  749.   vtype m_name;
  750.   char tmp_str[2];
  751.  
  752.   flag = FALSE;
  753.   get_flags(typ, &weapon_type, &harm_type, &dummy);
  754.   oldy = y;
  755.   oldx = x;
  756.   dist = 0;
  757.   do
  758.     {
  759.       (void) move(dir, &y, &x);
  760.       if (test_light(oldy, oldx))
  761.     lite_spot(oldy, oldx);
  762.       else
  763.     unlite_spot(oldy, oldx);
  764.       dist++;
  765.       if (dist > OBJ_BOLT_RANGE)
  766.     flag = TRUE;
  767.       else
  768.     {
  769.       c_ptr = &cave[y][x];
  770.       if (c_ptr->fopen)
  771.         {
  772.           if (c_ptr->cptr > 1)
  773.         {
  774.           flag = TRUE;
  775.           m_ptr = &m_list[c_ptr->cptr];
  776.           r_ptr = &c_list[m_ptr->mptr];
  777.           /* light it up first, then check to see if visible */
  778.           m_list[c_ptr->cptr].ml = TRUE;
  779.           lower_monster_name(m_name, m_ptr, r_ptr);
  780.           (void) sprintf(out_val, "The %s strikes %s.", bolt_typ,
  781.               m_name);
  782.           msg_print(out_val);
  783.           if (harm_type & r_ptr->cdefense)
  784.             dam = dam*2;
  785.           else if (weapon_type & r_ptr->spells)
  786.             dam = (dam/4.0);
  787.           i = mon_take_hit((int)c_ptr->cptr, dam);
  788.           monster_name(m_name, m_ptr, r_ptr);
  789.           if (i >= 0)
  790.             {
  791.               (void) sprintf(out_val, "%s dies in a fit of agony.",
  792.                   m_name);
  793.               msg_print(out_val);
  794.             }
  795.           else
  796.             {
  797.               if (panel_contains(y, x))
  798.             {
  799.               tmp_str[0] = c_list[m_ptr->mptr].cchar;
  800.               tmp_str[1] = '\0';
  801.               print(tmp_str, y, x);
  802.             }
  803.               if (dam > 0)
  804.             {
  805.               (void) sprintf (out_val, "%s screams in agony.",
  806.                       m_name);
  807.               msg_print (out_val);
  808.             }
  809.             }
  810.         }
  811.           else if (panel_contains(y, x))
  812.         {
  813.           print("*", y, x);
  814.           /* show the bolt */
  815.           put_qio();
  816.         }
  817.         }
  818.       else
  819.         flag = TRUE;
  820.     }
  821.       oldy = y;
  822.       oldx = x;
  823.     }
  824.   while (!flag);
  825. }
  826.  
  827.  
  828. /* Shoot a ball in a given direction.  Note that balls have an    */
  829. /* area affect....                                       -RAK-   */
  830. int fire_ball(typ, dir, y, x, dam_hp, descrip)
  831. int typ, dir, y, x, dam_hp;
  832. ctype descrip;
  833. {
  834.   register int i, j;
  835.   int dam, max_dis, thit, tkill, k;
  836.   int oldy, oldx, dist;
  837.   int weapon_type, harm_type;
  838.   int flag;
  839.   int (*destroy)();
  840.   register cave_type *c_ptr;
  841.   register monster_type *m_ptr;
  842.   register creature_type *r_ptr;
  843.   vtype out_val;
  844.   char tmp_str[2];
  845.  
  846.   thit   = 0;
  847.   tkill  = 0;
  848.   max_dis = 2;
  849.   get_flags(typ, &weapon_type, &harm_type, &destroy);
  850.   flag = FALSE;
  851.   oldy = y;
  852.   oldx = x;
  853.   dist = 0;
  854.   do
  855.     {
  856.       (void) move(dir, &y, &x);
  857.       dist++;
  858.       if (test_light(oldy, oldx))
  859.     lite_spot(oldy, oldx);
  860.       else
  861.     unlite_spot(oldy, oldx);
  862.       if (dist > OBJ_BOLT_RANGE)
  863.     flag = TRUE;
  864.       else
  865.     {
  866.       c_ptr = &cave[y][x];
  867.       if ((!c_ptr->fopen) || (c_ptr->cptr > 1))
  868.         {
  869.           flag = TRUE;
  870.           if (!c_ptr->fopen)
  871.         {
  872.           y = oldy;
  873.           x = oldx;
  874.         }
  875.           /* The ball hits and explodes...                 */
  876.           /* The explosion...                      */
  877.           for (i = y-max_dis; i <= y+max_dis; i++)
  878.         for (j = x-max_dis; j <= x+max_dis; j++)
  879.           if (in_bounds(i, j))
  880.             if (distance(y, x, i, j) <= max_dis)
  881.               if (los(y, x, i, j))     /* FIXED BUG V4.5        */
  882.             {
  883.               c_ptr = &cave[i][j];
  884.               if (c_ptr->tptr != 0)
  885.                 if ((*destroy)(t_list[c_ptr->tptr].tval))
  886.                   (void) delete_object(i, j);
  887.               if (c_ptr->fopen)
  888.                 {
  889.                   if (panel_contains(i, j))  print("*", i, j);
  890.                   if (c_ptr->cptr > 1)
  891.                 {
  892.                   m_ptr = &m_list[c_ptr->cptr];
  893.                   r_ptr = &c_list[m_ptr->mptr];
  894.                   thit++;
  895.                   dam = dam_hp;
  896.                   if (harm_type & r_ptr->cdefense)
  897.                     dam = dam*2;
  898.                   else if (weapon_type & r_ptr->spells)
  899.                     dam = dam / 4;
  900.                   dam = (dam/(distance(i, j, y, x)+1));
  901.                   k = mon_take_hit((int)c_ptr->cptr, dam);
  902.                   if (k >= 0)
  903.                     tkill++;
  904.                   else
  905.                     {
  906.                       if (panel_contains(i, j))
  907.                     {
  908.                       tmp_str[0] = r_ptr->cchar;
  909.                       tmp_str[1] = '\0';
  910.                       print(tmp_str, i, j);
  911.                       m_ptr->ml = TRUE;
  912.                     }
  913.                     }
  914.                 }
  915.                 }
  916.             }
  917.           /* show ball of whatever */
  918.           put_qio();
  919.  
  920.           for (i = (y - 2); i <= (y + 2); i++)
  921.         for (j = (x - 2); j <= (x + 2); j++)
  922.           if (in_bounds(i, j))
  923.             if (panel_contains(i, j))
  924.               if (distance(y, x, i, j) <= max_dis)
  925.             {
  926.               c_ptr = &cave[i][j];
  927.               if (test_light(i, j))
  928.                 lite_spot(i, j);
  929.               else if (c_ptr->cptr == 1)
  930.                 lite_spot(i, j);
  931.               else if (c_ptr->cptr > 1)
  932.                 if (m_list[c_ptr->cptr].ml)
  933.                   lite_spot(i, j);
  934.                 else
  935.                   unlite_spot(i, j);
  936.               else
  937.                 unlite_spot(i, j);
  938.             }
  939.           /* End  explosion...                     */
  940.           if (thit == 1)
  941.         {
  942.           (void) sprintf(out_val,
  943.                  "The %s envelopes a creature!",
  944.                  descrip);
  945.           msg_print(out_val);
  946.         }
  947.           else if (thit > 1)
  948.         {
  949.           (void) sprintf(out_val,
  950.                  "The %s envelopes several creatures!",
  951.                  descrip);
  952.           msg_print(out_val);
  953.         }
  954.           if (tkill == 1)
  955.         msg_print("There is a scream of agony!");
  956.           else if (tkill > 1)
  957.         msg_print("There are several screams of agony!");
  958.           /* End ball hitting...                   */
  959.         }
  960.       else if (panel_contains(y, x))
  961.         {
  962.           print("*", y, x);
  963.           /* show bolt */
  964.           put_qio();
  965.         }
  966.       oldy = y;
  967.       oldx = x;
  968.     }
  969.     }
  970.   while (!flag);
  971. }
  972.  
  973.  
  974. /* Breath weapon works like a fire_ball, but affects the player. */
  975. /* Note the area affect....                              -RAK-   */
  976. breath(typ, y, x, dam_hp, ddesc)
  977. int typ, y, x, dam_hp;
  978. char *ddesc;
  979. {
  980.   register int i, j;
  981.   int dam, max_dis;
  982.   int weapon_type, harm_type;
  983.   int (*destroy)();
  984.   register cave_type *c_ptr;
  985.   register monster_type *m_ptr;
  986.   register creature_type *r_ptr;
  987.  
  988.   max_dis = 2;
  989.   get_flags(typ, &weapon_type, &harm_type, &destroy);
  990.   for (i = y-2; i <= y+2; i++)
  991.     for (j = x-2; j <= x+2; j++)
  992.       if (in_bounds(i, j))
  993.     if (distance(y, x, i, j) <= max_dis)
  994.       {
  995.         c_ptr = &cave[i][j];
  996.         if (c_ptr->tptr != 0)
  997.           if ((*destroy)(t_list[c_ptr->tptr].tval))
  998.         (void) delete_object(i, j);
  999.         if (c_ptr->fopen)
  1000.           {
  1001.         if (panel_contains(i, j))
  1002.           print("*", i, j);
  1003.         if (c_ptr->cptr > 1)
  1004.           {
  1005.             m_ptr = &m_list[c_ptr->cptr];
  1006.             r_ptr = &c_list[m_ptr->mptr];
  1007.             dam = dam_hp;
  1008.             if (harm_type & r_ptr->cdefense)
  1009.               dam = dam*2;
  1010.             else if (weapon_type & r_ptr->spells)
  1011.               dam = (dam/4.0);
  1012.             dam = (dam/(distance(i, j, y, x)+1));
  1013.             m_ptr->hp = m_ptr->hp - dam;
  1014.             m_ptr->csleep = 0;
  1015.             if (m_ptr->hp < 0)
  1016.               {
  1017.             monster_death((int)m_ptr->fy, (int)m_ptr->fx,
  1018.                       r_ptr->cmove);
  1019.             delete_monster((int)c_ptr->cptr);
  1020.               }
  1021.           }
  1022.         else if (c_ptr->cptr == 1)
  1023.           {
  1024.             dam = (dam_hp/(distance(i, j, y, x)+1));
  1025.             /* let's do at least one point of damage */
  1026.                     /* prevents randint(0) problem with poison_gas, also */
  1027.                     if (dam == 0)
  1028.                       dam = 1;
  1029.             switch(typ)
  1030.               {
  1031.               case 1: light_dam(dam, ddesc); break;
  1032.               case 2: poison_gas(dam, ddesc); break;
  1033.               case 3: acid_dam(dam, ddesc); break;
  1034.               case 4: cold_dam(dam, ddesc); break;
  1035.               case 5: fire_dam(dam, ddesc); break;
  1036.               }
  1037.           }
  1038.           }
  1039.       }
  1040.   /* show the ball of gas */
  1041.   put_qio();
  1042.  
  1043.   for (i = (y - 2); i <= (y + 2); i++)
  1044.     for (j = (x - 2); j <= (x + 2); j++)
  1045.       if (in_bounds(i, j))
  1046.     if (panel_contains(i, j))
  1047.       if (distance(y, x, i, j) <= max_dis)
  1048.         {
  1049.           c_ptr = &cave[i][j];
  1050.           if (test_light(i, j))
  1051.         lite_spot(i, j);
  1052.           else if (c_ptr->cptr == 1)
  1053.         lite_spot(i, j);
  1054.           else if (c_ptr->cptr > 1)
  1055.         if (m_list[c_ptr->cptr].ml)
  1056.           lite_spot(i, j);
  1057.         else
  1058.           unlite_spot(i, j);
  1059.           else
  1060.         unlite_spot(i, j);
  1061.         }
  1062. }
  1063.  
  1064.  
  1065. /* Recharge a wand, staff, or rod.  Sometimes the item breaks. -RAK-*/
  1066. int recharge(num)
  1067. register int num;
  1068. {
  1069.   int item_val;
  1070.   int redraw;
  1071.   register int res;
  1072.   register treasure_type *i_ptr;
  1073.  
  1074.   res = FALSE;
  1075.   redraw = FALSE;
  1076.   if (get_item(&item_val, "Recharge which item?", &redraw, 0, inven_ctr-1))
  1077.     {
  1078.       i_ptr = &inventory[item_val];
  1079.       if ((i_ptr->tval == 55) || (i_ptr->tval == 60) || (i_ptr->tval == 65))
  1080.     /* recharge I = recharge(20) = 1/6 failure */
  1081.     /* recharge II = recharge(60) = 1/10 failure */
  1082.     if (randint((num + 40)/10) == 1)
  1083.       {
  1084.         res = TRUE;
  1085.         msg_print("There is a bright flash of light...");
  1086.         inven_destroy(item_val);
  1087.       }
  1088.     else
  1089.       {
  1090.         res = TRUE;
  1091.         num = (num/(i_ptr->level+2)) + 1;
  1092.         i_ptr->p1 += 2 + randint(num);
  1093.         if (index(i_ptr->name, '^') == 0)
  1094.           insert_str(i_ptr->name, " (%P1", "^ (%P1");
  1095.       }
  1096.     }
  1097.   if (redraw)
  1098.     {
  1099.       /* make sure player sees message before draw cave erases it */
  1100.       msg_print(" ");
  1101.       draw_cave();
  1102.     }
  1103.   return(res);
  1104. }
  1105.  
  1106.  
  1107. /* Increase or decrease a creatures hit points        -RAK-    */
  1108. int hp_monster(dir, y, x, dam)
  1109. int dir, y, x, dam;
  1110. {
  1111.   register int i;
  1112.   int flag;
  1113.   int monster;
  1114.   cave_type *c_ptr;
  1115.   monster_type *m_ptr;
  1116.   creature_type *r_ptr;
  1117.   vtype out_val;
  1118.   vtype m_name;
  1119.  
  1120.   monster = FALSE;
  1121.   flag = FALSE;
  1122.   do
  1123.     {
  1124.       (void) move(dir, &y, &x);
  1125.       c_ptr = &cave[y][x];
  1126.       if (c_ptr->fopen)
  1127.     {
  1128.       if (c_ptr->cptr > 1)
  1129.         {
  1130.           flag = TRUE;
  1131.           m_ptr = &m_list[c_ptr->cptr];
  1132.           r_ptr = &c_list[m_ptr->mptr];
  1133.           monster_name (m_name, m_ptr, r_ptr);
  1134.           monster = TRUE;
  1135.           i = mon_take_hit((int)c_ptr->cptr, dam);
  1136.           if (i >= 0)
  1137.         {
  1138.           (void) sprintf(out_val, "%s dies in a fit of agony.",
  1139.               m_name);
  1140.           msg_print(out_val);
  1141.         }
  1142.           else
  1143.         {
  1144.           if (dam > 0)
  1145.             {
  1146.               (void) sprintf(out_val, "%s screams in agony.",
  1147.                      m_name);
  1148.               msg_print(out_val);
  1149.             }
  1150.         }
  1151.         }
  1152.     }
  1153.       else
  1154.     flag = TRUE;
  1155.     }
  1156.   while (!flag);
  1157.   return(monster);
  1158. }
  1159.  
  1160.  
  1161. /* Drains life; note it must be living...        -RAK-    */
  1162. int drain_life(dir, y, x)
  1163. int dir, y, x;
  1164. {
  1165.   register int i;
  1166.   int flag;
  1167.   int drain;
  1168.   register cave_type *c_ptr;
  1169.   register monster_type *m_ptr;
  1170.   register creature_type *r_ptr;
  1171.   vtype out_val;
  1172.   vtype m_name;
  1173.  
  1174.   drain = FALSE;
  1175.   flag = FALSE;
  1176.   do
  1177.     {
  1178.       (void) move(dir, &y, &x);
  1179.       c_ptr = &cave[y][x];
  1180.       if (c_ptr->fopen)
  1181.     {
  1182.       if (c_ptr->cptr > 1)
  1183.         {
  1184.           flag = TRUE;
  1185.           m_ptr = &m_list[c_ptr->cptr];
  1186.           r_ptr = &c_list[m_ptr->mptr];
  1187.           if ((r_ptr->cdefense & 0x0008) == 0)
  1188.         {
  1189.           drain = TRUE;
  1190.           monster_name (m_name, m_ptr, r_ptr);
  1191.           i = mon_take_hit((int)c_ptr->cptr, 50);
  1192.           if (i >= 0)
  1193.             {
  1194.               (void) sprintf(out_val, "%s dies in a fit of agony.",
  1195.                   m_name);
  1196.               msg_print(out_val);
  1197.             }
  1198.           else
  1199.             {
  1200.               (void) sprintf(out_val, "%s screams in agony.",
  1201.                   m_name);
  1202.               msg_print(out_val);
  1203.             }
  1204.         }
  1205.         }
  1206.       else
  1207.         flag = TRUE;
  1208.     }
  1209.     }
  1210.   while (!flag);
  1211.   return(drain);
  1212. }
  1213.  
  1214.  
  1215. /* Increase or decrease a creatures speed        -RAK-    */
  1216. /* NOTE: cannot slow a winning creature (BALROG)                 */
  1217. int speed_monster(dir, y, x, spd)
  1218. int dir, y, x, spd;
  1219. {
  1220.   int speed;
  1221.   int flag;
  1222.   register cave_type *c_ptr;
  1223.   register monster_type *m_ptr;
  1224.   register creature_type *r_ptr;
  1225.   vtype out_val;
  1226.   vtype m_name;
  1227.  
  1228.   speed = FALSE;
  1229.   flag = FALSE;
  1230.   do
  1231.     {
  1232.       (void) move(dir, &y, &x);
  1233.       c_ptr = &cave[y][x];
  1234.       if (c_ptr->fopen)
  1235.     {
  1236.       if (c_ptr->cptr > 1)
  1237.         {
  1238.           flag = TRUE;
  1239.           m_ptr = &m_list[c_ptr->cptr];
  1240.           r_ptr = &c_list[m_ptr->mptr];
  1241.           monster_name (m_name, m_ptr, r_ptr);
  1242.           if (spd > 0)
  1243.         {
  1244.           m_ptr->cspeed += spd;
  1245.           m_ptr->csleep = 0;
  1246.           (void) sprintf (out_val, "%s starts moving faster.", m_name);
  1247.           msg_print (out_val);
  1248.           speed = TRUE;
  1249.         }
  1250.           else if (randint(MAX_MONS_LEVEL) > r_ptr->level)
  1251.         {
  1252.           m_ptr->cspeed += spd;
  1253.           m_ptr->csleep = 0;
  1254.           (void) sprintf (out_val, "%s starts moving slower.", m_name);
  1255.           msg_print (out_val);
  1256.           speed = TRUE;
  1257.         }
  1258.           else
  1259.         {
  1260.           (void) sprintf(out_val, "%s is unaffected.", m_name);
  1261.           msg_print(out_val);
  1262.         }
  1263.         }
  1264.     }
  1265.       else
  1266.     flag = TRUE;
  1267.     }
  1268.   while (!flag);
  1269.   return(speed);
  1270. }
  1271.  
  1272.  
  1273. /* Confuse a creature                    -RAK-    */
  1274. int confuse_monster(dir, y, x)
  1275. int dir, y, x;
  1276. {
  1277.   int flag;
  1278.   int confuse;
  1279.   register cave_type *c_ptr;
  1280.   register monster_type *m_ptr;
  1281.   register creature_type *r_ptr;
  1282.   vtype out_val;
  1283.   vtype m_name;
  1284.  
  1285.   confuse = FALSE;
  1286.   flag = FALSE;
  1287.   do
  1288.     {
  1289.       (void) move(dir, &y, &x);
  1290.       c_ptr = &cave[y][x];
  1291.       if (c_ptr->fopen)
  1292.     {
  1293.       if (c_ptr->cptr > 1)
  1294.         {
  1295.           m_ptr = &m_list[c_ptr->cptr];
  1296.           r_ptr = &c_list[m_ptr->mptr];
  1297.           monster_name (m_name, m_ptr, r_ptr);
  1298.           flag = TRUE;
  1299.           if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
  1300.           (0x1000 & r_ptr->cdefense))
  1301.         {
  1302.           (void) sprintf(out_val, "%s is unaffected.", m_name);
  1303.           msg_print(out_val);
  1304.         }
  1305.           else
  1306.         {
  1307.           m_ptr->confused = TRUE;
  1308.           confuse = TRUE;
  1309.           m_ptr->csleep = 0;
  1310.           (void) sprintf(out_val, "%s appears confused.", m_name);
  1311.           msg_print(out_val);
  1312.         }
  1313.         }
  1314.     }
  1315.       else
  1316.     flag = TRUE;
  1317.     }
  1318.   while (!flag);
  1319.   return(confuse);
  1320. }
  1321.  
  1322.  
  1323. /* Sleep a creature...                    -RAK-    */
  1324. int sleep_monster(dir, y, x)
  1325. int dir, y, x;
  1326. {
  1327.   int flag;
  1328.   int sleep;
  1329.   register cave_type *c_ptr;
  1330.   register monster_type *m_ptr;
  1331.   register creature_type *r_ptr;
  1332.   vtype out_val;
  1333.   vtype m_name;
  1334.  
  1335.   sleep = FALSE;
  1336.   flag = FALSE;
  1337.   do
  1338.     {
  1339.       (void) move(dir, &y, &x);
  1340.       c_ptr = &cave[y][x];
  1341.       if (c_ptr->fopen)
  1342.     {
  1343.       if (c_ptr->cptr > 1)
  1344.         {
  1345.           m_ptr = &m_list[c_ptr->cptr];
  1346.           r_ptr = &c_list[m_ptr->mptr];
  1347.           flag = TRUE;
  1348.           monster_name (m_name, m_ptr, r_ptr);
  1349.           if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
  1350.           (0x1000 & r_ptr->cdefense))
  1351.         {
  1352.           (void) sprintf(out_val, "%s is unaffected.", m_name);
  1353.           msg_print(out_val);
  1354.         }
  1355.           else
  1356.         {
  1357.           m_ptr->csleep = 500;
  1358.           sleep = TRUE;
  1359.           (void) sprintf(out_val, "%s falls asleep.", m_name);
  1360.           msg_print(out_val);
  1361.         }
  1362.         }
  1363.     }
  1364.       else
  1365.     flag = TRUE;
  1366.     }
  1367.   while (!flag);
  1368.   return(sleep);
  1369. }
  1370.  
  1371.  
  1372. /* Turn stone to mud, delete wall....            -RAK-    */
  1373. int wall_to_mud(dir, y, x)
  1374. int dir, y, x;
  1375. {
  1376.   int i;
  1377.   vtype out_val, tmp_str;
  1378.   register int flag;
  1379.   int wall;
  1380.   register cave_type *c_ptr;
  1381.   register monster_type *m_ptr;
  1382.   register creature_type *r_ptr;
  1383.   vtype m_name;
  1384.  
  1385.   wall = FALSE;
  1386.   flag = FALSE;
  1387.   do
  1388.     {
  1389.       (void) move(dir, &y, &x);
  1390.       c_ptr = &cave[y][x];
  1391.       if (in_bounds(y, x))
  1392.     {
  1393.       if ((c_ptr->fval >= 10) && (c_ptr->fval <= 12))
  1394.         {
  1395.           flag = TRUE;
  1396.           (void) twall(y, x, 1, 0);
  1397.           if (test_light(y, x))
  1398.         {
  1399.           msg_print("The wall turns into mud.");
  1400.           wall = TRUE;
  1401.         }
  1402.         }
  1403.       else if ((c_ptr->tptr != 0) && (!c_ptr->fopen))
  1404.         {
  1405.           flag = TRUE;
  1406.           if (panel_contains(y, x))
  1407.         if (test_light(y, x))
  1408.           {
  1409.             inventory[INVEN_MAX] = t_list[c_ptr->tptr];
  1410.             objdes(tmp_str, INVEN_MAX, FALSE);
  1411.             (void) sprintf(out_val, "The %s turns into mud.", tmp_str);
  1412.             msg_print(out_val);
  1413.             wall = TRUE;
  1414.           }
  1415.           (void) delete_object(y, x);
  1416.         }
  1417.       if (c_ptr->cptr > 1)
  1418.         {
  1419.           m_ptr = &m_list[c_ptr->cptr];
  1420.           r_ptr = &c_list[m_ptr->mptr];
  1421.           if (0x0200 & r_ptr->cdefense)
  1422.         {
  1423.           monster_name (m_name, m_ptr, r_ptr);
  1424.           i = mon_take_hit((int)c_ptr->cptr, 100);
  1425.           flag = TRUE;
  1426.           if (i >= 0)
  1427.             {
  1428.               (void) sprintf(out_val, "%s dies in a fit of agony.",
  1429.                      m_name);
  1430.               msg_print(out_val);
  1431.             }
  1432.           else
  1433.             {
  1434.               (void) sprintf(out_val, "%s wails out in pain!", m_name);
  1435.               msg_print(out_val);
  1436.             }
  1437.         }
  1438.         }
  1439.     }
  1440.       else
  1441.     flag = TRUE;
  1442.     }
  1443.   while (!flag);
  1444.   return(wall);
  1445. }
  1446.  
  1447.  
  1448. /* Destroy all traps and doors in a given direction    -RAK-    */
  1449. int td_destroy2(dir, y, x)
  1450. int dir, y, x;
  1451. {
  1452.   register int destroy2;
  1453.   register cave_type *c_ptr;
  1454.   register treasure_type *t_ptr;
  1455.  
  1456.   destroy2 = FALSE;
  1457.   do
  1458.     {
  1459.       (void) move(dir, &y, &x);
  1460.       c_ptr = &cave[y][x];
  1461.       if (c_ptr->tptr != 0)
  1462.     {
  1463.       t_ptr = &t_list[c_ptr->tptr];
  1464.       if ((t_ptr->tval == 2) || (t_ptr->tval == 101) ||
  1465.           (t_ptr->tval == 102) || (t_ptr->tval == 104) ||
  1466.           (t_ptr->tval == 105) || (t_ptr->tval == 109))
  1467.         {
  1468.           if (delete_object(y, x))
  1469.         {
  1470.           msg_print("There is a bright flash of light!");
  1471.           c_ptr->fopen = TRUE;
  1472.           destroy2 = TRUE;
  1473.         }
  1474.         }
  1475.     }
  1476.     }
  1477.   while (cave[y][x].fopen);
  1478.   return(destroy2);
  1479. }
  1480.  
  1481.  
  1482. /* Polymorph a monster                    -RAK-    */
  1483. /* NOTE: cannot polymorph a winning creature (BALROG)            */
  1484. int poly_monster(dir, y, x)
  1485. int dir, y, x;
  1486. {
  1487.   int dist;
  1488.   int flag;
  1489.   int poly;
  1490.   register cave_type *c_ptr;
  1491.   register creature_type *r_ptr;
  1492.   register monster_type *m_ptr;
  1493.   vtype out_val;
  1494.   vtype m_name;
  1495.  
  1496.   poly = FALSE;
  1497.   flag = FALSE;
  1498.   dist = 0;
  1499.   do
  1500.     {
  1501.       (void) move(dir, &y, &x);
  1502.       dist++;
  1503.       if (dist <= OBJ_BOLT_RANGE)
  1504.     {
  1505.       c_ptr = &cave[y][x];
  1506.       if (c_ptr->fopen)
  1507.         {
  1508.           if (c_ptr->cptr > 1)
  1509.         {
  1510.           m_ptr = &m_list[c_ptr->cptr];
  1511.           r_ptr = &c_list[m_ptr->mptr];
  1512.           if (randint(MAX_MONS_LEVEL) > r_ptr->level)
  1513.             {
  1514.               flag = TRUE;
  1515.               delete_monster((int)c_ptr->cptr);
  1516.               place_monster(y, x,
  1517.               randint(m_level[MAX_MONS_LEVEL]) - 1 + m_level[0],
  1518.                     FALSE);
  1519.               if (panel_contains(y, x))
  1520.             if (test_light(y, x))
  1521.               poly = TRUE;
  1522.             }
  1523.           else
  1524.             {
  1525.               monster_name (m_name, m_ptr, r_ptr);
  1526.               (void) sprintf(out_val, "%s is unaffected.", m_name);
  1527.               msg_print(out_val);
  1528.             }
  1529.         }
  1530.           else
  1531.         flag = TRUE;
  1532.         }
  1533.     }
  1534.       else
  1535.     flag = TRUE;
  1536.     }
  1537.   while (!flag);
  1538.   return(poly);
  1539. }
  1540.  
  1541.  
  1542. /* Create a wall...                    -RAK-    */
  1543. int build_wall(dir, y, x)
  1544. int dir, y, x;
  1545. {
  1546.   register int i;
  1547.   int build;
  1548.   register cave_type *c_ptr;
  1549.  
  1550.   build = FALSE;
  1551.   i = 0;
  1552.   (void) move(dir, &y, &x);
  1553.   while ((cave[y][x].fopen) && (i < 10))
  1554.     {
  1555.       c_ptr = &cave[y][x];
  1556.       if (c_ptr->tptr != 0)
  1557.     (void) delete_object(y, x);
  1558.       if (c_ptr->cptr > 1)
  1559.     /* what happens to this monster ? */
  1560.     (void) mon_take_hit((int)c_ptr->cptr, damroll("2d8"));
  1561.       c_ptr->fval  = rock_wall2.ftval;
  1562.       c_ptr->fopen = rock_wall2.ftopen;
  1563.       c_ptr->fm = FALSE;
  1564.       if (test_light(y, x))
  1565.     lite_spot(y, x);
  1566.       i++;
  1567.       build = TRUE;
  1568.       (void) move(dir, &y, &x);
  1569.     }
  1570.   return(build);
  1571. }
  1572.  
  1573.  
  1574. /* Replicate a creature                    -RAK-    */
  1575. int clone_monster(dir, y, x)
  1576. int dir, y, x;
  1577. {
  1578.   register int flag;
  1579.   register int clone;
  1580.   register cave_type *c_ptr;
  1581.  
  1582.   flag = FALSE;
  1583.   clone = FALSE;
  1584.   do
  1585.     {
  1586.       (void) move(dir, &y, &x);
  1587.       c_ptr = &cave[y][x];
  1588.       if (c_ptr->cptr > 1)
  1589.     {
  1590.       multiply_monster(y, x, (int)m_list[c_ptr->cptr].mptr, FALSE);
  1591.       if (panel_contains(y, x))
  1592.         if (m_list[c_ptr->cptr].ml)
  1593.           clone = TRUE;
  1594.       flag = TRUE;
  1595.     }
  1596.     }
  1597.   while ((cave[y][x].fopen) && (!flag));
  1598.   return(clone);
  1599. }
  1600.  
  1601.  
  1602. /* Move the creature record to a new location        -RAK-    */
  1603. teleport_away(monptr, dis)
  1604. int monptr, dis;
  1605. {
  1606.   register int yn, xn, ctr;
  1607.   register monster_type *m_ptr;
  1608.  
  1609.   m_ptr = &m_list[monptr];
  1610.   ctr = 0;
  1611.   do
  1612.     {
  1613.       do
  1614.     {
  1615.       yn = m_ptr->fy + (randint(2*dis+1) - (dis + 1));
  1616.       xn = m_ptr->fx + (randint(2*dis+1) - (dis + 1));
  1617.     }
  1618.       while (!in_bounds(yn, xn));
  1619.       ctr++;
  1620.       if (ctr > 9)
  1621.     {
  1622.       ctr = 0;
  1623.       dis += 5;
  1624.     }
  1625.     }
  1626.   while ((!cave[yn][xn].fopen) || (cave[yn][xn].cptr != 0));
  1627.   move_rec((int)m_ptr->fy, (int)m_ptr->fx, yn, xn);
  1628.   if (test_light((int)m_ptr->fy, (int)m_ptr->fx))
  1629.     lite_spot((int)m_ptr->fy, (int)m_ptr->fx);
  1630.   m_ptr->fy = yn;
  1631.   m_ptr->fx = xn;
  1632.   m_ptr->ml = FALSE;
  1633. }
  1634.  
  1635.  
  1636. /* Teleport player to spell casting creature        -RAK-    */
  1637. teleport_to(ny, nx)
  1638. int ny, nx;
  1639. {
  1640.   int dis, ctr, y, x;
  1641.   register int i, j;
  1642.   register cave_type *c_ptr;
  1643.  
  1644.   dis = 1;
  1645.   ctr = 0;
  1646.   do
  1647.     {
  1648.       y = ny + (randint(2*dis+1) - (dis + 1));
  1649.       x = nx + (randint(2*dis+1) - (dis + 1));
  1650.       ctr++;
  1651.       if (ctr > 9)
  1652.     {
  1653.       ctr = 0;
  1654.       dis++;
  1655.     }
  1656.     }
  1657.   while ((!cave[y][x].fopen) || (cave[y][x].cptr >= 2));
  1658.   move_rec(char_row, char_col, y, x);
  1659.   for (i = char_row-1; i <= char_row+1; i++)
  1660.     for (j = char_col-1; j <= char_col+1; j++)
  1661.       {
  1662.     c_ptr = &cave[i][j];
  1663.     c_ptr->tl = FALSE;
  1664.     if (!test_light(i, j))
  1665.       unlite_spot(i, j);
  1666.       }
  1667.   if (test_light(char_row, char_col))
  1668.     lite_spot(char_row, char_col);
  1669.   char_row = y;
  1670.   char_col = x;
  1671.   move_char(5);
  1672.   /* light creatures */
  1673.   creatures(FALSE);
  1674. }
  1675.  
  1676.  
  1677. /* Teleport all creatures in a given direction away    -RAK-    */
  1678. int teleport_monster(dir, y, x)
  1679. int dir, y, x;
  1680. {
  1681.   register int flag;
  1682.   register int teleport;
  1683.   register cave_type *c_ptr;
  1684.  
  1685.   flag = FALSE;
  1686.   teleport = FALSE;
  1687.   do
  1688.     {
  1689.       (void) move(dir, &y, &x);
  1690.       c_ptr = &cave[y][x];
  1691.       if (c_ptr->cptr > 1)
  1692.     {
  1693.       teleport_away((int)c_ptr->cptr, MAX_SIGHT);
  1694.       teleport = TRUE;
  1695.     }
  1696.     }
  1697.   while ((cave[y][x].fopen) && (!flag));
  1698.   return(teleport);
  1699. }
  1700.  
  1701.  
  1702. /* Delete all creatures within max_sight distance    -RAK-    */
  1703. /* NOTE : Winning creatures cannot be genocided                  */
  1704. int mass_genocide()
  1705. {
  1706.   register int i, j;
  1707.   int genocide;
  1708.   register monster_type *m_ptr;
  1709.   register creature_type *r_ptr;
  1710.  
  1711.   genocide = FALSE;
  1712.   i = muptr;
  1713.   while (i > 0)
  1714.     {
  1715.       m_ptr = &m_list[i];
  1716.       r_ptr = &c_list[m_ptr->mptr];
  1717.       j = m_ptr->nptr;
  1718.       if (m_ptr->cdis <= MAX_SIGHT)
  1719.     if ((r_ptr->cmove & 0x80000000) == 0)
  1720.       {
  1721.         delete_monster(i);
  1722.         genocide = TRUE;
  1723.       }
  1724.       i = j;
  1725.     }
  1726.   return(genocide);
  1727. }
  1728.  
  1729.  
  1730. /* Delete all creatures of a given type from level.    -RAK-    */
  1731. /* This does not keep creatures of type from appearing later.    */
  1732. /* NOTE : Winning creatures can not be genocided. */
  1733. int genocide()
  1734. {
  1735.   register int i, j;
  1736.   char typ;
  1737.   register monster_type *m_ptr;
  1738.   register creature_type *r_ptr;
  1739.   vtype out_val;
  1740.  
  1741.   i = muptr;
  1742.   if (get_com("What kind of creature shall be exterminated?", &typ))
  1743.     while (i > 0)
  1744.       {
  1745.     m_ptr = &m_list[i];
  1746.     r_ptr = &c_list[m_ptr->mptr];
  1747.     j = m_ptr->nptr;
  1748.     if (typ == c_list[m_ptr->mptr].cchar)
  1749.       if ((r_ptr->cmove & 0x80000000) == 0)
  1750.         delete_monster(i);
  1751.       else
  1752.         {
  1753.           /* genocide is a powerful spell, so we will let the player
  1754.          know the names of the creatures he did not destroy,
  1755.          this message makes no sense otherwise */
  1756.           (void) sprintf(out_val, "The %s is unaffected.", r_ptr->name);
  1757.           msg_print(out_val);
  1758.         }
  1759.     i = j;
  1760.       }
  1761.   return(TRUE);
  1762. }
  1763.  
  1764.  
  1765. /* Change speed of any creature player can see....    -RAK-    */
  1766. /* NOTE: cannot slow a winning creature (BALROG)                 */
  1767. int speed_monsters(spd)
  1768. int spd;
  1769. {
  1770.   register int i, j;
  1771.   int speed;
  1772.   register monster_type *m_ptr;
  1773.   register creature_type *r_ptr;
  1774.   vtype out_val;
  1775.   vtype m_name;
  1776.  
  1777.   i = muptr;
  1778.   speed = FALSE;
  1779.   while (i > 0)
  1780.     {
  1781.       m_ptr = &m_list[i];
  1782.       j = m_ptr->nptr;
  1783.       if (m_ptr->ml)
  1784.     {
  1785.       r_ptr = &c_list[m_ptr->mptr];
  1786.       monster_name (m_name, m_ptr, r_ptr);
  1787.       if (spd > 0)
  1788.         {
  1789.           m_ptr->cspeed += spd;
  1790.           m_ptr->csleep = 0;
  1791.           speed = TRUE;
  1792.           (void) sprintf (out_val, "%s starts moving faster.", m_name);
  1793.           msg_print (out_val);
  1794.         }
  1795.       else if (randint(MAX_MONS_LEVEL) > r_ptr->level)
  1796.         {
  1797.           m_ptr->cspeed += spd;
  1798.           m_ptr->csleep = 0;
  1799.           (void) sprintf (out_val, "%s starts moving slower.", m_name);
  1800.           msg_print (out_val);
  1801.           speed = TRUE;
  1802.         }
  1803.       else
  1804.         {
  1805.           (void) sprintf(out_val, "%s is unaffected.", m_name);
  1806.           msg_print(out_val);
  1807.         }
  1808.     }
  1809.       i = j;
  1810.     }
  1811.   return(speed);
  1812. }
  1813.  
  1814.  
  1815. /* Sleep any creature that player can see        -RAK-    */
  1816. int sleep_monsters2()
  1817. {
  1818.   register int i, j;
  1819.   int sleep;
  1820.   register monster_type *m_ptr;
  1821.   register creature_type *r_ptr;
  1822.   vtype out_val;
  1823.   vtype m_name;
  1824.  
  1825.   i = muptr;
  1826.   sleep = FALSE;
  1827.   while (i > 0)
  1828.     {
  1829.       m_ptr = &m_list[i];
  1830.       r_ptr = &c_list[m_ptr->mptr];
  1831.       monster_name (m_name, m_ptr, r_ptr);
  1832.       j = m_ptr->nptr;
  1833.       if (m_ptr->ml)
  1834.     {
  1835.       if ((randint(MAX_MONS_LEVEL) < r_ptr->level) ||
  1836.           (0x1000 & r_ptr->cdefense))
  1837.         {
  1838.           (void) sprintf(out_val, "%s is unaffected.", m_name);
  1839.           msg_print(out_val);
  1840.         }
  1841.       else
  1842.         {
  1843.           m_ptr->csleep = 500;
  1844.           (void) sprintf(out_val, "%s falls asleep.", m_name);
  1845.           msg_print(out_val);
  1846.           sleep = TRUE;
  1847.         }
  1848.     }
  1849.       i = j;
  1850.     }
  1851.   return(sleep);
  1852. }
  1853.  
  1854.  
  1855. /* Polymorph any creature that player can see...     -RAK-    */
  1856. /* NOTE: cannot polymorph a winning creature (BALROG)            */
  1857. int mass_poly()
  1858. {
  1859.   register int i, j;
  1860.   int y, x;
  1861.   int mass;
  1862.   register monster_type *m_ptr;
  1863.   register creature_type *r_ptr;
  1864.  
  1865.   i = muptr;
  1866.   mass = FALSE;
  1867.   while (i > 0)
  1868.     {
  1869.       m_ptr = &m_list[i];
  1870.       j = m_ptr->nptr;
  1871.       if (m_ptr->cdis < MAX_SIGHT)
  1872.     {
  1873.       r_ptr = &c_list[m_ptr->mptr];
  1874.       if ((r_ptr->cmove & 0x80000000) == 0)
  1875.         {
  1876.           y = m_ptr->fy;
  1877.           x = m_ptr->fx;
  1878.           delete_monster(i);
  1879.           place_monster(y, x, randint(m_level[MAX_MONS_LEVEL]) - 1
  1880.                 + m_level[0], FALSE);
  1881.           mass = TRUE;
  1882.         }
  1883.     }
  1884.       i = j;
  1885.     }
  1886.   return(mass);
  1887. }
  1888.  
  1889.  
  1890. /* Display evil creatures on current panel        -RAK-    */
  1891. int detect_evil()
  1892. {
  1893.   register int i;
  1894.   int flag;
  1895.   register monster_type *m_ptr;
  1896.   char temp_str[2];
  1897.  
  1898.   flag = FALSE;
  1899.   i = muptr;
  1900.   while (i > 0)
  1901.     {
  1902.       m_ptr = &m_list[i];
  1903.       if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx))
  1904.     if (0x0004 & c_list[m_ptr->mptr].cdefense)
  1905.       {
  1906.         m_ptr->ml = TRUE;
  1907.         temp_str[0] = c_list[m_ptr->mptr].cchar;
  1908.         temp_str[1] = '\0';
  1909.         print(temp_str, (int)m_ptr->fy, (int)m_ptr->fx);
  1910.         flag = TRUE;
  1911.       }
  1912.       i = m_list[i].nptr;
  1913.     }
  1914.   if (flag)
  1915.     {
  1916.       msg_print("You sense the presence of evil!");
  1917.       /* make sure player sees the message */
  1918.       msg_print(" ");
  1919.       msg_flag = FALSE;
  1920.     }
  1921.   return(flag);
  1922. }
  1923.  
  1924.  
  1925. /* Change players hit points in some manner        -RAK-    */
  1926. int hp_player(num, kind)
  1927. int num;
  1928. char *kind;
  1929. {
  1930.   register int res;
  1931.   register struct misc *m_ptr;
  1932.  
  1933.   res = FALSE;
  1934.   m_ptr = &py.misc;
  1935.   if (num < 0)
  1936.     {
  1937.       take_hit(num, kind);
  1938.       if (m_ptr->chp < 0)
  1939.     msg_print("You feel your life slipping away!");
  1940.       res = TRUE;
  1941.     }
  1942.   else if (m_ptr->chp < m_ptr->mhp)
  1943.     {
  1944.       m_ptr->chp += (double)num;
  1945.       if (m_ptr->chp > m_ptr->mhp)
  1946.     m_ptr->chp = (double)m_ptr->mhp;
  1947.       prt_chp();
  1948.       switch(num/5)
  1949.     {
  1950.     case 0:
  1951.       msg_print("You feel a little better.");
  1952.       break;
  1953.     case 1: case 2:
  1954.       msg_print("You feel better.");
  1955.       break;
  1956.     case 3: case 4: case 5: case 6:
  1957.       msg_print("You feel much better.");
  1958.       break;
  1959.     default:
  1960.       msg_print("You feel very good.");
  1961.       break;
  1962.     }
  1963.       res = TRUE;
  1964.     }
  1965.   return(res);
  1966. }
  1967.  
  1968.  
  1969. /* Cure players confusion                -RAK-    */
  1970. int cure_confusion()
  1971. {
  1972.   register int cure;
  1973.   register struct flags *f_ptr;
  1974.  
  1975.   cure = FALSE;
  1976.   f_ptr = &py.flags;
  1977.   if (f_ptr->confused > 1)
  1978.     {
  1979.       f_ptr->confused = 1;
  1980.       cure = TRUE;
  1981.     }
  1982.   return(cure);
  1983. }
  1984.  
  1985.  
  1986. /* Cure players blindness                -RAK-    */
  1987. int cure_blindness()
  1988. {
  1989.   register int cure;
  1990.   register struct flags *f_ptr;
  1991.  
  1992.   cure = FALSE;
  1993.   f_ptr = &py.flags;
  1994.   if (f_ptr->blind > 1)
  1995.     {
  1996.       f_ptr->blind = 1;
  1997.       cure = TRUE;
  1998.     }
  1999.   return(cure);
  2000. }
  2001.  
  2002.  
  2003. /* Cure poisoning                    -RAK-    */
  2004. int cure_poison()
  2005. {
  2006.   register int cure;
  2007.   register struct flags *f_ptr;
  2008.  
  2009.   cure = FALSE;
  2010.   f_ptr = &py.flags;
  2011.   if (f_ptr->poisoned > 1)
  2012.     {
  2013.       f_ptr->poisoned = 1;
  2014.       cure = TRUE;
  2015.     }
  2016.   return(cure);
  2017. }
  2018.  
  2019.  
  2020. /* Cure the players fear                 -RAK-    */
  2021. int remove_fear()
  2022. {
  2023.   register int remove;
  2024.   register struct flags *f_ptr;
  2025.  
  2026.   remove = FALSE;
  2027.   f_ptr = &py.flags;
  2028.   if (f_ptr->afraid > 1)
  2029.     {
  2030.       f_ptr->afraid = 1;
  2031.       remove = TRUE;
  2032.     }
  2033.   return(remove);
  2034. }
  2035.  
  2036.  
  2037. /* This is a fun one.  In a given block, pick some walls and    */
  2038. /* turn them into open spots.  Pick some open spots and turn     */
  2039. /* them into walls.  An "Earthquake" effect...           -RAK-   */
  2040. int earthquake()
  2041. {
  2042.   register int i, j;
  2043.   register cave_type *c_ptr;
  2044.  
  2045.   for (i = char_row-8; i <= char_row+8; i++)
  2046.     for (j = char_col-8; j <= char_col+8; j++)
  2047.       if ((i != char_row) || (j != char_col))
  2048.     if (in_bounds(i, j))
  2049.       if (randint(8) == 1)
  2050.         {
  2051.           c_ptr = &cave[i][j];
  2052.           if (c_ptr->tptr != 0)
  2053.         (void) delete_object(i, j);
  2054.           if (c_ptr->cptr > 1)
  2055.         /* what happens to this monster ? */
  2056.         (void) mon_take_hit((int)c_ptr->cptr, damroll("2d8"));
  2057.           if ((c_ptr->fval >= 10) && (c_ptr->fval <= 12))
  2058.         {
  2059.           if (next_to4(i, j, 1, 2, -1) > 0)
  2060.             {
  2061.               c_ptr->fval  = corr_floor2.ftval;
  2062.               c_ptr->fopen = corr_floor2.ftopen;
  2063.             }
  2064.           else
  2065.             {
  2066.               c_ptr->fval  = corr_floor1.ftval;
  2067.               c_ptr->fopen = corr_floor1.ftopen;
  2068.             }
  2069.           if (test_light(i, j))
  2070.             unlite_spot(i, j);
  2071.           c_ptr->pl = FALSE;
  2072.           c_ptr->fm = FALSE;
  2073.           if (c_ptr->tl)
  2074.             lite_spot(i, j);
  2075.         }
  2076.           else if (set_floor(c_ptr->fval))
  2077.         {
  2078.           switch(randint(10))
  2079.             {
  2080.             case 1: case 2: case 3: case 4: case 5:
  2081.               c_ptr->fval  = rock_wall3.ftval;
  2082.               c_ptr->fopen = rock_wall3.ftopen;
  2083.               break;
  2084.             case 6: case 7: case 8:
  2085.               c_ptr->fval  = rock_wall2.ftval;
  2086.               c_ptr->fopen = rock_wall2.ftopen;
  2087.               break;
  2088.             case 9: case 10:
  2089.               c_ptr->fval  = rock_wall1.ftval;
  2090.               c_ptr->fopen = rock_wall1.ftopen;
  2091.               break;
  2092.             }
  2093.           c_ptr->fm = FALSE;
  2094.         }
  2095.           if (test_light(i, j))
  2096.         lite_spot(i, j);
  2097.         }
  2098.   return(TRUE);
  2099. }
  2100.  
  2101.  
  2102. /* Evil creatures don't like this...                     -RAK-   */
  2103. int protect_evil()
  2104. {
  2105.   register struct flags *f_ptr;
  2106.  
  2107.   f_ptr = &py.flags;
  2108.   f_ptr->protevil += randint(25) + 3*py.misc.lev;
  2109.   return(TRUE);
  2110. }
  2111.  
  2112.  
  2113. /* Create some high quality mush for the player.     -RAK-    */
  2114. int create_food()
  2115. {
  2116.   register cave_type *c_ptr;
  2117.  
  2118.   c_ptr = &cave[char_row][char_col];
  2119.   if (c_ptr->tptr != 0)
  2120.     {
  2121.       /* take no action here, don't want to destroy object under player */
  2122.       msg_print ("There is already an object under you.");
  2123.       /* set reset_flag so that scroll/spell points won't be used */
  2124.       reset_flag = TRUE;
  2125.     }
  2126.   else
  2127.     {
  2128.       place_object(char_row, char_col);
  2129.       t_list[c_ptr->tptr] = mush;
  2130.     }
  2131.   return (TRUE);
  2132. }
  2133.  
  2134.  
  2135. /* Attempts to destroy a type of creature.  Success depends on    */
  2136. /* the creatures level VS. the player's level            -RAK-   */
  2137. int dispell_creature(cflag, damage)
  2138. int cflag;
  2139. int damage;
  2140. {
  2141.   register int i, m_next;
  2142.   vtype out_val;
  2143.   register monster_type *m_ptr;
  2144.   register creature_type *r_ptr;
  2145.   register struct misc *p_ptr;
  2146.   int dispel;
  2147.   vtype m_name;
  2148.  
  2149.   i = muptr;
  2150.   dispel = FALSE;
  2151.   while (i > 0)
  2152.     {
  2153.       m_next = m_list[i].nptr;
  2154.       m_ptr = &m_list[i];
  2155.       if (m_ptr->ml)
  2156.     if (cflag & c_list[m_ptr->mptr].cdefense)
  2157.       {
  2158.         m_ptr->hp -= randint(damage);
  2159.         m_ptr->csleep = 0;
  2160.         r_ptr = &c_list[m_ptr->mptr];
  2161.         monster_name (m_name, m_ptr, r_ptr);
  2162.         if (m_ptr->hp < 0)
  2163.           {
  2164.         (void) sprintf(out_val, "%s dissolves!", m_name);
  2165.         msg_print(out_val);
  2166.         monster_death((int)m_ptr->fy, (int)m_ptr->fx,
  2167.                   c_list[m_ptr->mptr].cmove);
  2168.         p_ptr = &py.misc;
  2169.         p_ptr->exp += ((r_ptr->mexp*(r_ptr->level/p_ptr->lev)) + 0.5);
  2170.         delete_monster(i);
  2171.           }
  2172.         else
  2173.           {
  2174.         (void) sprintf(out_val, "%s shudders.", m_name);
  2175.         msg_print(out_val);
  2176.           }
  2177.         dispel = TRUE;
  2178.       }
  2179.       i = m_next;
  2180.     }
  2181.   return(dispel);
  2182. }
  2183.  
  2184.  
  2185. /* Attempt to turn (confuse) undead creatures...     -RAK-    */
  2186. int turn_undead()
  2187. {
  2188.   register int i;
  2189.   int turn_und;
  2190.   register monster_type *m_ptr;
  2191.   register creature_type *r_ptr;
  2192.   vtype out_val;
  2193.   vtype m_name;
  2194.  
  2195.   i = muptr;
  2196.   turn_und = FALSE;
  2197.   while (i > 0)
  2198.     {
  2199.       m_ptr = &m_list[i];
  2200.       r_ptr = &c_list[m_ptr->mptr];
  2201.       if (panel_contains((int)m_ptr->fy, (int)m_ptr->fx))
  2202.     if (m_ptr->ml)
  2203.       if (0x0008 & r_ptr->cdefense)
  2204.         {
  2205.           monster_name (m_name, m_ptr, r_ptr);
  2206.           if (((py.misc.lev+1) > r_ptr->level) ||
  2207.           (randint(5) == 1))
  2208.         {
  2209.           (void) sprintf(out_val, "%s runs frantically!", m_name);
  2210.           msg_print(out_val);
  2211.           m_ptr->confused = TRUE;
  2212.           turn_und = TRUE;
  2213.         }
  2214.           else
  2215.         {
  2216.           (void) sprintf(out_val, "%s is unaffected.", m_name);
  2217.           msg_print(out_val);
  2218.         }
  2219.         }
  2220.       i = m_list[i].nptr;
  2221.     }
  2222.   return(turn_und);
  2223. }
  2224.  
  2225.  
  2226. /* Leave a glyph of warding... Creatures will not pass over! -RAK-*/
  2227. int warding_glyph()
  2228. {
  2229.   int i;
  2230.   register cave_type *c_ptr;
  2231.  
  2232.   c_ptr = &cave[char_row][char_col];
  2233.   if (c_ptr->tptr == 0)
  2234.     {
  2235.       popt(&i);
  2236.       c_ptr->tptr = i;
  2237.       t_list[i] = scare_monster;
  2238.     }
  2239.   return(TRUE);
  2240. }
  2241.  
  2242.  
  2243. /* Lose a strength point.                -RAK-    */
  2244. int lose_str()
  2245. {
  2246.   if (!py.flags.sustain_str)
  2247.     {
  2248.       py.stats.cstr = de_statp(py.stats.cstr);
  2249.       msg_print("You feel very sick.");
  2250.       prt_strength();
  2251.       /* adjust misc stats */
  2252.       py_bonuses(blank_treasure, 0);
  2253.     }
  2254.   else
  2255.     msg_print("You feel sick for a moment,  it passes.");
  2256.   return(TRUE);
  2257. }
  2258.  
  2259.  
  2260. /* Lose an intelligence point.                -RAK-    */
  2261. int lose_int()
  2262. {
  2263.   if (!py.flags.sustain_int)
  2264.     {
  2265.       py.stats.cint = de_statp(py.stats.cint);
  2266.       msg_print("You become very dizzy.");
  2267.       prt_intelligence();
  2268.     }
  2269.   else
  2270.     msg_print("You become dizzy for a moment,  it passes.");
  2271.   return(TRUE);
  2272. }
  2273.  
  2274.  
  2275. /* Lose a wisdom point.                    -RAK-    */
  2276. int lose_wis()
  2277. {
  2278.   if (!py.flags.sustain_wis)
  2279.     {
  2280.       py.stats.cwis = de_statp(py.stats.cwis);
  2281.       msg_print("You feel very naive.");
  2282.       prt_wisdom();
  2283.     }
  2284.   else
  2285.     msg_print("You feel naive for a moment,  it passes.");
  2286.   return(TRUE);
  2287. }
  2288.  
  2289.  
  2290. /* Lose a dexterity point.                -RAK-    */
  2291. int lose_dex()
  2292. {
  2293.   if (!py.flags.sustain_dex)
  2294.     {
  2295.       py.stats.cdex = de_statp(py.stats.cdex);
  2296.       msg_print("You feel very sore.");
  2297.       prt_dexterity();
  2298.       /* adjust misc stats */
  2299.       py_bonuses(blank_treasure, 0);
  2300.     }
  2301.   else
  2302.     msg_print("You feel sore for a moment,  it passes.");
  2303.   return(TRUE);
  2304. }
  2305.  
  2306.  
  2307. /* Lose a constitution point.                -RAK-    */
  2308. int lose_con()
  2309. {
  2310.   if (!py.flags.sustain_con)
  2311.     {
  2312.       py.stats.ccon = de_statp(py.stats.ccon);
  2313.       msg_print("You feel very sick.");
  2314.       prt_constitution();
  2315.     }
  2316.   else
  2317.     msg_print("You feel sick for a moment,  it passes.");
  2318.   return(TRUE);
  2319. }
  2320.  
  2321.  
  2322. /* Lose a charisma point.                -RAK-    */
  2323. int lose_chr()
  2324. {
  2325.   if (!py.flags.sustain_chr)
  2326.     {
  2327.       py.stats.cchr = de_statp(py.stats.cchr);
  2328.       msg_print("Your skin starts to itch.");
  2329.       prt_charisma();
  2330.     }
  2331.   else
  2332.     msg_print("Your skin starts to itch, but feels better now.");
  2333.   return(TRUE);
  2334. }
  2335.  
  2336.  
  2337. /* Lose experience                    -RAK-    */
  2338. lose_exp(amount)
  2339. int amount;
  2340. {
  2341.   register int i, j;
  2342.   int av_hp, lose_hp;
  2343.   int av_mn, lose_mn;
  2344.   register struct misc *m_ptr;
  2345.   register class_type *c_ptr;
  2346.   int num_known, adjust, num_allowed, num_lose;
  2347.   double avg_spells;
  2348.  
  2349.   m_ptr = &py.misc;
  2350.   if (amount > m_ptr->exp)
  2351.     m_ptr->exp = 0;
  2352.   else
  2353.     m_ptr->exp -= amount;
  2354.   i = 1;
  2355.   while ((player_exp[i-1]*m_ptr->expfact) <= m_ptr->exp)
  2356.     i++;
  2357.   j = m_ptr->lev - i;
  2358.   while (j > 0)
  2359.     {
  2360.       av_hp = (int)((double)m_ptr->mhp/(double)m_ptr->lev + 0.5);
  2361.       av_mn = (int)((double)m_ptr->mana/(double)m_ptr->lev + 0.5);
  2362.       m_ptr->lev--;
  2363.       j--;
  2364.       lose_hp = randint(av_hp*2-1);
  2365.       lose_mn = randint(av_mn*2-1);
  2366.       m_ptr->mhp  -= lose_hp;
  2367.       m_ptr->mana -= lose_mn;
  2368.       if (m_ptr->mhp  < 1)  m_ptr->mhp  = 1;
  2369.       if (m_ptr->mana < 0)  m_ptr->mana = 0;
  2370.  
  2371.       /* perhaps lose some spells, depending on current int/wis and level */
  2372.       c_ptr = &class[m_ptr->pclass];
  2373.       if ((c_ptr->mspell) || (c_ptr->pspell))
  2374.     {
  2375.       /* count spells known */
  2376.       num_known = 0;
  2377.       for (i = 0; i < 31; i++)
  2378.         if (magic_spell[m_ptr->pclass][i].learned)
  2379.           num_known++;
  2380.       
  2381.       /* calculate number of spells allowed */
  2382.       if (c_ptr->mspell)
  2383.         adjust = int_adj();
  2384.       else
  2385.         adjust = wis_adj();
  2386.       switch (adjust)
  2387.         {
  2388.         case 0: avg_spells = 0.0; break;
  2389.         case 1: avg_spells = 1.0; break;
  2390.         case 2: avg_spells = 1.0; break;
  2391.         case 3: avg_spells = 1.0; break;
  2392.         case 4: avg_spells = 1.5; break;
  2393.         case 5: avg_spells = 1.5; break;
  2394.         case 6: avg_spells = 2.0; break;
  2395.         case 7: avg_spells = 2.5; break;
  2396.         default: avg_spells = 1.0; break;
  2397.         }
  2398.       num_allowed = (int)(m_ptr->lev * avg_spells + 0.5);
  2399.       num_lose = num_known - num_allowed;
  2400.  
  2401.       /* forget spells until both:
  2402.          number known is less than or equal to number allowed
  2403.          and highest spell level is lower than or equal to player level */
  2404.       i = 30;
  2405.       while (((magic_spell[m_ptr->pclass][i].slevel > m_ptr->lev)
  2406.           || (num_lose > 0))
  2407.          && (i >= 0))
  2408.         {
  2409.           if (magic_spell[m_ptr->pclass][i].learned)
  2410.         {
  2411.           magic_spell[m_ptr->pclass][i].learned = FALSE;
  2412.           num_lose--;
  2413.           if (c_ptr->mspell)
  2414.             msg_print("You have forgotten a magic spell!");
  2415.           else
  2416.             msg_print("You have forgotten a prayer!");
  2417.         }
  2418.           i--;
  2419.         }
  2420.     }
  2421.     }
  2422.   if (m_ptr->chp > m_ptr->mhp)
  2423.     m_ptr->chp = (double)m_ptr->mhp;
  2424.   if (m_ptr->cmana > m_ptr->mana)
  2425.     m_ptr->cmana = (double)m_ptr->mana;
  2426.   (void) strcpy(m_ptr->title, player_title[m_ptr->pclass][m_ptr->lev-1]);
  2427.   prt_experience();
  2428.   prt_mhp();
  2429.   prt_chp();
  2430.   prt_cmana();
  2431.   prt_level();
  2432.   prt_title();
  2433. }
  2434.  
  2435.  
  2436. /* Slow Poison                        -RAK-    */
  2437. int slow_poison()
  2438. {
  2439.   register int slow;
  2440.   register struct flags *f_ptr;
  2441.  
  2442.   slow = FALSE;
  2443.   f_ptr = &py.flags;
  2444.   if (f_ptr->poisoned > 0)
  2445.     {
  2446.       f_ptr->poisoned = f_ptr->poisoned / 2.0;
  2447.       if (f_ptr->poisoned < 1)  f_ptr->poisoned = 1;
  2448.       slow = TRUE;
  2449.       msg_print("The effects of the poison has been reduced.");
  2450.     }
  2451.   return(slow);
  2452. }
  2453.  
  2454.  
  2455. /* Bless                         -RAK-    */
  2456. int bless(amount)
  2457. int amount;
  2458. {
  2459.   py.flags.blessed += amount;
  2460.   return(TRUE);
  2461. }
  2462.  
  2463.  
  2464. /* Detect Invisible for period of time            -RAK-    */
  2465. detect_inv2(amount)
  2466. int amount;
  2467. {
  2468.   py.flags.detect_inv += amount;
  2469. }
  2470.  
  2471.  
  2472. replace_spot(y, x, typ)
  2473. int y, x, typ;
  2474. {
  2475.   register cave_type *c_ptr;
  2476.  
  2477.   c_ptr = &cave[y][x];
  2478.   switch(typ)
  2479.     {
  2480.     case 1: case 2: case 3:
  2481.       c_ptr->fval  = corr_floor1.ftval;
  2482.       c_ptr->fopen = corr_floor1.ftopen;
  2483.       break;
  2484.     case 4: case 7: case 10:
  2485.       c_ptr->fval  = rock_wall1.ftval;
  2486.       c_ptr->fopen = rock_wall1.ftopen;
  2487.       break;
  2488.     case 5: case 8: case 11:
  2489.       c_ptr->fval  = rock_wall2.ftval;
  2490.       c_ptr->fopen = rock_wall2.ftopen;
  2491.       break;
  2492.     case 6: case 9: case 12:
  2493.       c_ptr->fval  = rock_wall3.ftval;
  2494.       c_ptr->fopen = rock_wall3.ftopen;
  2495.       break;
  2496.     }
  2497.   c_ptr->pl = FALSE;
  2498.   c_ptr->fm = FALSE;
  2499.   if (c_ptr->tptr != 0)
  2500.     (void) delete_object(y, x);
  2501.   if (c_ptr->cptr > 1)
  2502.     delete_monster((int)c_ptr->cptr);
  2503. }
  2504.  
  2505.  
  2506. /* The spell of destruction...                -RAK-    */
  2507. /* NOTE : Winning creatures that are deleted will be considered  */
  2508. /*        as teleporting to another level.  This will NOT win the*/
  2509. /*        game...                                                */
  2510. int destroy_area(y, x)
  2511. register int y, x;
  2512. {
  2513.   register int i, j, k;
  2514.  
  2515.   if (dun_level > 0)
  2516.     {
  2517.       for (i = (y-15); i <= (y+15); i++)
  2518.     for (j = (x-15); j <= (x+15); j++)
  2519.       if (in_bounds(i, j))
  2520.         if (cave[i][j].fval != 15)
  2521.           {
  2522.         k = distance(i, j, y, x);
  2523.         if (k < 13)
  2524.           replace_spot(i, j, randint(6));
  2525.         else if (k < 16)
  2526.           replace_spot(i, j, randint(9));
  2527.           }
  2528.     }
  2529.   msg_print("There is a searing blast of light!");
  2530.   py.flags.blind += 10 + randint(10);
  2531.   return(TRUE);
  2532. }
  2533.  
  2534.  
  2535. /* Enchants a plus onto an item...            -RAK-    */
  2536. int enchant(plusses)
  2537. worlint *plusses;
  2538. {
  2539.   register int chance;
  2540.   register int res;
  2541.  
  2542.   chance = 0;
  2543.   res = FALSE;
  2544.   if (*plusses > 0)
  2545.     switch(*plusses)
  2546.       {
  2547.       case 1:  chance = 040; break;
  2548.       case 2:  chance = 100; break;
  2549.       case 3:  chance = 200; break;
  2550.       case 4:  chance = 400; break;
  2551.       case 5:  chance = 600; break;
  2552.       case 6:  chance = 700; break;
  2553.       case 7:  chance = 800; break;
  2554.       case 8:  chance = 900; break;
  2555.       case 9:  chance = 950; break;
  2556.       default: chance = 995; break;
  2557.       }
  2558.   if (randint(1000) > chance)
  2559.     {
  2560.       *plusses += 1;
  2561.       res = TRUE;
  2562.     }
  2563.   return(res);
  2564. }
  2565.  
  2566.  
  2567. /* Removes curses from items in inventory        -RAK-    */
  2568. int remove_curse()
  2569. {
  2570.   register int i;
  2571.   register int remove;
  2572.   register treasure_type *i_ptr;
  2573.  
  2574.   remove = FALSE;
  2575.   for (i = 22; i <= 31; i++)
  2576.     {
  2577.       i_ptr = &inventory[i];
  2578.       if (0x80000000 & i_ptr->flags)
  2579.     {
  2580.       i_ptr->flags &= 0x7FFFFFFF;
  2581.       py_bonuses(blank_treasure, 0);
  2582.       remove = TRUE;
  2583.     }
  2584.     }
  2585.   return(remove);
  2586. }
  2587.  
  2588.  
  2589. /* Restores any drained experience            -RAK-    */
  2590. int restore_level()
  2591. {
  2592.   register int restore;
  2593.   register struct misc *m_ptr;
  2594.  
  2595.   restore = FALSE;
  2596.   m_ptr = &py.misc;
  2597.   if (m_ptr->max_exp > m_ptr->exp)
  2598.     {
  2599.       restore = TRUE;
  2600.       msg_print("You feel your life energies returning...");
  2601.       m_ptr->exp = m_ptr->max_exp;
  2602.       prt_experience();
  2603.     }
  2604.   return(restore);
  2605. }
  2606.